package com.jackie.coupon.claculation.controller;

import com.alibaba.fastjson.JSON;
import com.jackie.coupon.claculation.api.ShoppingCart;
import com.jackie.coupon.claculation.api.SimulationOrder;
import com.jackie.coupon.claculation.api.SimulationResponse;
import com.jackie.coupon.claculation.services.CouponCalculationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * CouponCalculationController
 *
 * @author Jackie Hou
 * @date 2023/11/17 17:05
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("calculator")
public class CouponCalculationController {

    /**
     * 计算订单价格
     * @param cart
     * @return
     */
    @PostMapping("/checkout")
    @ResponseBody
    public ShoppingCart calculateOrderPrice(@RequestBody ShoppingCart cart) {
        log.info("do calculation {}", JSON.toJSONString(cart));
        return couponCalculationService.calculateOrderPrice(cart);
    }


    /**
     * 试算
     * @param order
     * @return
     */
    public SimulationResponse simulate(@RequestBody SimulationOrder order) {
        return null;
    }

    @Autowired
    private CouponCalculationService couponCalculationService;
}
